package com.singularity.common.controller;

import cn.dev33.satoken.util.SaResult;

import com.singularity.common.domain.dto.user.UserInfoDTO;
import com.singularity.common.domain.param.user.CaptchaLoginParam;
import com.singularity.common.domain.param.user.PasswordLoginParam;
import com.singularity.common.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 天
 *
 * @description: 登录控制层
 */
@RestController
@Api(tags = "登录相关")
public class LoginController {

    private final LoginService loginService;

    @Autowired
    public LoginController(LoginService loginService) {
        this.loginService = loginService;
    }

    @ApiOperation("账号密码登录")
    @RequestMapping(method = RequestMethod.POST,value = "/backstageLogin/password")
    public SaResult loginByPassword(@RequestBody PasswordLoginParam passwordLoginParam){
        UserInfoDTO userInfoDTO = loginService.loginByPassword(passwordLoginParam);
        return new SaResult(SaResult.CODE_SUCCESS,"登录成功",userInfoDTO);
    }

    @ApiOperation("注销")
    @RequestMapping(method = RequestMethod.POST,value = "/logout")
    public SaResult logout(){
        loginService.logout();
        return SaResult.ok("注销成功");
    }
}
